#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<algorithm>

using namespace std;
const int N = 1010;
struct node
{
	int index;
	int cnt;
}row[N], col[N];

int m, n, k, l, d;

bool cmp1(node& n1, node& n2)
{
	return n1.cnt > n2.cnt;
}
bool cmp2(node& n1, node& n2)
{
	return n1.index < n2.index;
}
int main()
{
	cin >> m >> n >> k >> l >> d;
	for (int i = 1; i <= m; i++) row[i].index = i;
	for (int i = 1; i <= n; i++) col[i].index = i;
	while (d--)
	{
		int x, y, p, q;
		cin >> x >> y >> p >> q;
		if (x == p) col[min(y, q)].cnt++;
		else row[min(x, p)].cnt++;
	}
	sort(row + 1, row + 1 + m, cmp1);
	sort(col + 1, col + 1 + n, cmp1);

	sort(row + 1, row + 1 + k, cmp2);
	sort(col + 1, col + 1 + l, cmp2);

	for (int i = 1; i <= k; i++)
	{
		cout << row[i].index;
		if (i != k) cout << ' ';
	}
	cout << endl;
	for (int i = 1; i <= l; i++)
	{
		cout << col[i].index;
		if (i != l) cout << ' ';
	}
	return 0;
}